namespace('base.selectitem');

base.selectitem.init = function(){
	
};

base.selectitem.initSelectitemUpdatePage = function(){
	var selecttypeId = $('#selecttypeId').val();
	var moduleId = $('#moduleId').val();
	var parentId = $('#parentId')==null?null:$('#parentId').val();
	var btnAddSelectitem = $('#btnAddSelectitem');
	var tblBody = $('#selectitemList tbody');
	var pidTpl = (parentId==null)?'':'<input type="hidden" name="selectitems[###].parent.id" value="'+parentId+'"/>';
	var trTpl = [
		'<tr>',
			'<td>',
				'<input type="hidden" name="selectitems[###].module.id" value="'+moduleId+'" />',
				'<input type="hidden" name="selectitems[###].selecttype.id" value="'+selecttypeId+'" />',
				pidTpl,
			'</td>',
			'<td>',
				'<input type="text" name="selectitems[###].name" value=""/>',
			'</td>',
			'<td>',
				'<input type="text" name="selectitems[###].description" value=""/>',
			'</td>',
			'<td>',
			'<input type="text" class="width100" name="selectitems[###].dsporder" value="0"/>',
			'</td>',
			'<td>',
				'<input type="text" class="width100" name="selectitems[###].img" value=""/>',
			'</td>',
			'<td>',
				'<a href="javascript:;" onclick="alert(\'请先保存.\');">编辑子项</a>',
			'</td>',
			'<td>',
				'<a class="btn btn-danger btn-small" href="javascript:;" onclick="var tr = this.parentNode.parentNode; tr.parentNode.removeChild(tr);void(0);">删除</a>',
			'</td>',
		'</tr>'
	].join('');
	
	btnAddSelectitem.click(function(){
		var count = $('#selectitemList tbody tr').length;
		tblBody.append(trTpl.replace(/###/g, count));
	});
};